//
//  DBExercise.h
//  CareRingApp
//
//  Created by Linktop on 2023/7/17.
//

#import <Foundation/Foundation.h>
#import "DbManager.h"

NS_ASSUME_NONNULL_BEGIN

extern const int MAX_ERERCISE_ONE_DAY;
extern const int EXER_TAKE_DATA_SECONDS;

typedef NS_ENUM(NSUInteger, EXER_TYPE) {
    EXER_UNKNOW = 0,
    EXER_WALK = 1,  // 步行
    EXER_RUN = 2,   // 跑步
    
};

typedef NS_ENUM(NSUInteger, EXER_LEVEL) {
    LEVEL_EASY,     // 简单
    LEVEL_MODERATE,   // 中等
    LEVEL_HARD,     // 困难
};



 
@class ExercisePoint;

@interface DBExercise : NSObject

@property(assign, nonatomic, readonly)int rowId;
@property(strong, nonatomic, readonly)NSString *macAddress;
@property(strong, nonatomic)NSNumber *duration; // unit :minute
@property(strong, nonatomic)NSDate *startDate, *endDate;
@property(strong, nonatomic)NSString *formatTimeString; // yyyy-MM-dd startDate生成

@property(assign, nonatomic) EXER_TYPE exerType; //运动内容
@property(assign, nonatomic) EXER_LEVEL exerLevel; //运动强度

@property(strong, nonatomic)NSMutableArray<ExercisePoint *> *points;
@property(assign, nonatomic)BOOL shouldNotShowCurrentday; //当天不再显示在主页
@property(assign, nonatomic)BOOL hasBeenSyncData;  // 标记是否已同步过数据

-(BOOL)isEnd;
-(instancetype)initWith:(NSString  * _Nonnull)macAddress ;
-(void)insert:(void(^)(BOOL succ))complete;
-(void)updateEndDate:(void(^)(BOOL succ))complete;

-(void)updatePoints:(void(^)(BOOL succ))complete;
-(void)updateNotShow:(void(^)(BOOL succ))complete;

+(void)createTable;
+(void)dropTable;

-(NSString *)stringForLevel;
+(NSString *)stringForLevel:(EXER_LEVEL)lv;
-(NSString *)stringForExerType;
-(NSString *)durationString:(BOOL)isRealtime;
+(NSString *)durationString:(int)duration;

//+(void)queryBy:(NSString * _Nonnull)macAddressIn
//OrderBeTimeDesc:(BOOL)isDesc Year:(NSUInteger)year
//      Cpmplete:(void(^)(NSMutableArray<NSDictionary *> *results))cmpBlk;

+(void)queryBy:(NSString * _Nonnull)macAddressIn Year:(int)year OrderBeTimeDesc:(BOOL)isDesc Cpmplete:(void(^)(NSMutableArray<DBExercise *> *results))cmpBlk;

+(void)queryBy:(NSString * _Nonnull)macIn BeginDate:(NSDate *)beginDate EndDate:(NSDate *)enDate OrderBeTimeDesc:(BOOL)isDesc
      Cpmplete:(void(^)(NSMutableArray<DBExercise *> *results))cmpBlk;

// 更新数据同步的状态
+(void)updateSyncStateBy:(NSString *)account Time:(NSTimeInterval)time CMP:(void(^)(BOOL succ))complete;


-(void)queryPoints:(void(^)(NSMutableArray <ExercisePoint *> * points))cmpBLK;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

@end


@interface ExercisePoint : NSObject

@property(strong, nonatomic)NSNumber *time;
@property(strong, nonatomic)NSNumber *value;
@property(strong, nonatomic)NSNumber *step;


@end



NS_ASSUME_NONNULL_END
